package 二叉树最大深度;

import java.util.List;

/**
 * @author: zhengtao
 * @description: N叉树的最大深度
 * @version: 1.0
 * @date: 2022/10/29  17:37
 */
public class Demo559 {
    public int maxDepth(Node root) {

        return getDepth(root);

    }
    //递归三部曲
    //1.确定入参和返回值
    private int getDepth(Node root) {
        //返回条件
        if(root==null){
            return 0;
        }
        List<Node> children = root.children;
        int max=0;
        for (int j = 0; j < children.size(); j++) {
           max=Math.max(getDepth(children.get(j)),max);
        }
        return max+1;
    }

    // Definition for a Node.
class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};

}
